/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicio.practica10;

import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

/**
 *
 * @author manolo
 */
public class ClienteContador {

    public static void main(String[] args) throws IOException {
        int numPeticiones;
        int puerto = 2001;
        Scanner sc = new Scanner(System.in);
        long inicCronom, finCronom; // variables del cronometro  

        System.out.println("Introduzca el número de peticiones al servidor: ");
        numPeticiones = sc.nextInt();

        System.out.println("Realizando conexion...");
        for (int i = 0; 1 < numPeticiones; i++) {
            inicCronom = System.currentTimeMillis(); //se prepara el cronometro
            try (Socket cable = new Socket("localhost", puerto)) {
                System.out.println("Realizada conexion a " + cable);
                System.out.println("Cerrando conexion...");
                cable.close();
            }
            finCronom = System.currentTimeMillis();
            System.out.println("Conexión realizada en: " + (finCronom - inicCronom) + " mseg.");

        }

    }
}
